Includes/ Programme generieren
Es kommt nicht oft vor, aber wenn, ist es eine nervige Arbeit: Das Anlegen von mehreren Includes. Das Anlegen ist einfach: Per INSERT REPORT kann einfach ein Programm angelegt werden. Aber: Die Programme müssen auch immer einer Entwicklungsklasse zugeordnet und in einen Transportauftrag aufgenommen werden…
Hintergrund
I’d rather write code that writes code than write code
In einem Programm werden vorsorglich eine bestimmte Anzahl von Includes angelegt um darin eigenes Coding zu hinterlegen.
Mit der SO10 habe ich einen Standardtext angelegt, dessen Inhalt als Coding hinterlegt wird.
Um die 100 Includes nicht von Hand anlegen zu müssen, habe ich folgendes Programm geschrieben:
Coding
REPORT. *** DATA DATA gv_number TYPE n LENGTH 3. DATA gv_repid TYPE syrepid. DATA gv_repti TYPE repti. DATA gt_lines TYPE STANDARD TABLE OF tline. DATA gs_header TYPE thead. FIELD-SYMBOLS <line> TYPE tline. DATA gt_code TYPE STANDARD TABLE OF string. FIELD-SYMBOLS <code> TYPE string. DATA gt_text TYPE STANDARD TABLE OF textpool. FIELD-SYMBOLS <text> TYPE textpool. DATA gv_object_name TYPE trobj_name. *** Selection Screen PARAMETERS p_trkorr TYPE trkorr OBLIGATORY. PARAMETERS p_devcls TYPE devclass DEFAULT 'ZXYZ'. PARAMETERS p_txtnam TYPE tdobname DEFAULT 'ZSAMPLE_CODE'. PARAMETERS p_incnam TYPE syrepid DEFAULT 'ZZ_INCLUDE_$$$'. PARAMETERS p_inctxt TYPE repti DEFAULT 'Coding Nummer $$$'. PARAMETERS p_start TYPE n LENGTH 3 DEFAULT 100 OBLIGATORY. PARAMETERS p_stopp TYPE n LENGTH 3 DEFAULT 160 OBLIGATORY. START-OF-SELECTION. IF p_start > p_stopp. MESSAGE i000(oo) WITH 'Start > Stopp!'. STOP. ENDIF. *** set start number gv_number = p_start. *** read sample coding CALL FUNCTION 'READ_TEXT' EXPORTING id = 'ST' language = sy-langu name = p_txtnam object = 'TEXT' TABLES lines = gt_lines EXCEPTIONS OTHERS = 8. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. STOP. ENDIF. *** process all includes DO. *** Report name gv_repid = p_incnam. REPLACE '$$$' WITH gv_number INTO gv_repid. *** Report description gv_repti = p_inctxt. REPLACE '$$$' WITH gv_number INTO gv_repti. *** protocol WRITE: / gv_repid. gv_object_name = gv_repid. *** set code, replace &REPID& by reportname and $$$ by actual number CLEAR gt_code. LOOP AT gt_lines ASSIGNING <line>. APPEND INITIAL LINE TO gt_code ASSIGNING <code>. <code> = <line>-tdline. REPLACE '&REPID&' WITH gv_repid INTO <code>. REPLACE '$$$' WITH gv_number INTO <code>. ENDLOOP. *** Insert report INSERT REPORT gv_repid FROM gt_code PROGRAM TYPE 'I'. IF sy-subrc > 0. WRITE: 'NOK', sy-subrc. STOP. ELSE. WRITE: 'OK'. *** Insert textpool CLEAR gt_text. APPEND INITIAL LINE TO gt_text ASSIGNING <text>. <text>-id = 'R'. <text>-key = space. <text>-entry = gv_repti. <text>-length = 50. INSERT textpool gv_repid FROM gt_text. ENDIF. *** set development class PERFORM tadir_entry. *** Increase include number ADD 1 TO gv_number. IF gv_number > p_stopp. EXIT. ENDIF. ENDDO. *&---------------------------------------------------------------------* *& Form tadir_entry *&---------------------------------------------------------------------* FORM tadir_entry. DATA lv_tadir_objnam TYPE sobj_name. DATA lv_src_system TYPE srcsystem. lv_tadir_objnam = gv_object_name. lv_src_system = sy-sysid. *** generate TADIR-Entry CALL FUNCTION 'TR_TADIR_INTERFACE' EXPORTING wi_test_modus = ' ' wi_tadir_pgmid = 'R3TR' wi_tadir_object = 'PROG' wi_tadir_obj_name = lv_tadir_objnam wi_tadir_srcsystem = lv_src_system wi_tadir_author = sy-uname wi_tadir_devclass = p_devcls wi_set_genflag = 'X' EXCEPTIONS tadir_entry_not_existing = 1 tadir_entry_ill_type = 2 no_systemname = 3 no_systemtype = 4 original_system_conflict = 5 object_reserved_for_devclass = 6 object_exists_global = 7 object_exists_local = 8 object_is_distributed = 9 obj_specification_not_unique = 10 no_authorization_to_delete = 11 devclass_not_existing = 12 simultanious_set_remove_repair = 13 order_missing = 14 no_modification_of_head_syst = 15 pgmid_object_not_allowed = 16 masterlanguage_not_specified = 17 devclass_not_specified = 18 specify_owner_unique = 19 loc_priv_objs_no_repair = 20 gtadir_not_reached = 21 object_locked_for_order = 22 change_of_class_not_allowed = 23 no_change_from_sap_to_tmp = 24 OTHERS = 25. IF sy-subrc <> 0. *** protocol write: / 'Error TADIR-Entry', sy-subrc. stop. ELSE. *** Add object to transport order PERFORM transport. ENDIF. ENDFORM. "tadir_entry *&---------------------------------------------------------------------* *& Form transport *&---------------------------------------------------------------------* FORM transport. *** Data DATA: iko200 TYPE ko200, iorder TYPE trkorr, itask TYPE trkorr. *** Object iko200-pgmid = 'R3TR'. iko200-object = 'PROG'. iko200-objfunc = space. iko200-obj_name = gv_repid. *** Check object CALL FUNCTION 'TR_OBJECT_CHECK' EXPORTING wi_ko200 = iko200 EXCEPTIONS cancel_edit_other_error = 1 show_only_other_error = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 RAISING check. ELSE. *** Insert object CALL FUNCTION 'TR_OBJECT_INSERT' EXPORTING wi_order = p_trkorr wi_ko200 = iko200 EXCEPTIONS cancel_edit_other_error = 1 show_only_other_error = 2 OTHERS = 3. IF sy-subrc > 0. *** protocol WRITE: 'Transport Error Insert '. STOP. ELSE. *** commit changes COMMIT WORK. ENDIF. ENDIF. ENDFORM. "transport
Letzte Artikel von Enno Wulff (Alle anzeigen)
- Interview mit Björn Schulz (Software-Heroes.com) - 3. September 2024
- Daten aus ALV ermitteln - 3. September 2024
- So lange es den SAPGUI noch gibt… - 27. Juni 2024